package com.bos.common;

import com.auth0.jwt.internal.org.apache.commons.lang3.text.StrBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * create by luojie 2018/6/5
 */
public class StrUtil {
    //把string数据拼接成一个string(不带中括号的)
    public static String spliceStrFormList(String[] arr){
        StrBuilder sb=new StrBuilder();
        for (int i=0;i<arr.length;i++){
            if(i==arr.length-1){
                sb.append(arr[i]);
            }else {
                sb.append(arr[i]+",");
            }
        }
        return sb.toString();
    }

    //把string数据拼接成一个string(带中括号的)
    public static String spliceStrFormListWithBracket(String[] arr){
        StrBuilder sb=new StrBuilder();
        sb.append("[");
        for (int i=0;i<arr.length;i++){
            if(i==arr.length-1){
                sb.append(arr[i]);
            }else {
                sb.append(arr[i]+",");
            }
        }
        sb.append("]");
        return sb.toString();
    }

    public static List<String> splitStrToList(String str){
        List<String> list=new ArrayList<>();
        String newStr=str.substring(2,str.length()-2);
        String[] arr;
        arr=newStr.split("\",\"");
        for (int i=0;i<arr.length;i++){
            list.add(arr[i]);
        }
        return list;
    }
}
